package edu.cdnu.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import edu.cdnu.dao.PermissionDao;
import edu.cdnu.dao.TeacherDao;
import edu.cdnu.pojo.RolePojo;
import edu.cdnu.pojo.TeacherPojo;
import edu.cdnu.service.PermissionService;

/**
 * PermissionService 实现类
 * @author ASUS AsingZ
 */
@Service
// 开启事务
@Transactional
public class PermissionServiceImpl implements PermissionService {

	@Autowired
	private PermissionDao permissionDao;
	@Autowired
	private TeacherDao teacherDao;
	
	
	@Override
	public List<RolePojo> selectRoleList() {
		return permissionDao.selectRoleList();
	}

	@Override
	public int selectRoleIdByAccount(String account) {
		// 空值判断
		if(account == null||"".equals(account)) return -1;
		
		// 1. 查询数据库
		TeacherPojo teacherPojo=teacherDao.selectTeacherByAccount(account);
		
		// 2. 判断查询到没有 
		if(teacherPojo==null||teacherPojo.getRoleId()==null) {
			// 既不是 教师和班主任就是 教务管理员roleId-2
			return 2;
		} 
		
		// 3. 查询到有内容直接返回
		return teacherPojo.getRoleId();
	}
	
}
